//
//  CYInvestRecordProgressCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/22.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYInvestRecordProgressCell.h"



@implementation CYInvestRecordProgressCellObject

@end



@interface CYInvestRecordProgressCell ()

@property(nonatomic, strong)UIImageView *successImageView;
@property(nonatomic, strong)UILabel *successLabel;
@property(nonatomic, strong)UILabel *successDataLabel;
@property(nonatomic, strong)UIView *accountLine;
@property(nonatomic, strong)UIImageView *accountImageView;
@property(nonatomic, strong)UILabel *accountLabel;
@property(nonatomic, strong)UILabel *accountDateLabel;
@property(nonatomic, strong)UIView *outLine;
@property(nonatomic, strong)UIImageView *outImageView;
@property(nonatomic, strong)UILabel *outLabel;
@property(nonatomic, strong)UILabel *outDateLabel;
@property(nonatomic, strong)UIView *bearingLine;
@property(nonatomic, strong)UIImageView *bearingImageView;
@property(nonatomic, strong)UILabel *bearingLabel;
@property(nonatomic, strong)UILabel *bearingDateLabel;
@property(nonatomic, strong)UIView *inLine;
@property(nonatomic, strong)UIImageView *inImageView;
@property(nonatomic, strong)UILabel *inLabel;
@property(nonatomic, strong)UILabel *inDateLabel;

@end


@implementation CYInvestRecordProgressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.accountLine = [self line];
        [self.contentView addSubview:self.accountLine];
        
        self.outLine = [self line];
        [self.contentView addSubview:self.outLine];
        
        self.bearingLine = [self line];
        [self.contentView addSubview:self.bearingLine];
        
        self.inLine = [self line];
        [self.contentView addSubview:self.inLine];
        
        self.successImageView = [self stateImageView];
        [self.contentView addSubview:self.successImageView];
        
        self.successLabel = [self labelWithText:@"投资成功"];
        [self.contentView addSubview:self.successLabel];
        
        self.successDataLabel = [self dateLabel];
        [self.contentView addSubview:self.successDataLabel];
        
        self.accountImageView = [self stateImageView];
        [self.contentView addSubview:self.accountImageView];
        
        self.accountLabel = [self labelWithText:@"资金进入银行备用金账户"];
        [self.contentView addSubview:self.accountLabel];
        
        self.accountDateLabel = [self dateLabel];
        [self.contentView addSubview:self.accountDateLabel];
        
        self.outImageView = [self stateImageView];
        [self.contentView addSubview:self.outImageView];
        
        self.outLabel = [self labelWithText:@"打款给项目标的借款人"];
        [self.contentView addSubview:self.outLabel];
        
        self.outDateLabel = [self dateLabel];
        [self.contentView addSubview:self.outDateLabel];
        
        self.bearingImageView = [self stateImageView];
        [self.contentView addSubview:self.bearingImageView];
        
        self.bearingLabel = [self labelWithText:@"开始计息"];
        [self.contentView addSubview:self.bearingLabel];
        
        self.bearingDateLabel = [self dateLabel];
        [self.contentView addSubview:self.bearingDateLabel];
        
        self.inImageView = [self stateImageView];
        [self.contentView addSubview:self.inImageView];
        
        self.inLabel = [self labelWithText:@"项目标的借款人还款"];
        [self.contentView addSubview:self.inLabel];
        
        self.inDateLabel = [self dateLabel];
        [self.contentView addSubview:self.inDateLabel];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 346;
}

- (BOOL)shouldUpdateCellWithObject:(CYInvestRecordProgressCellObject *)object
{
    self.successDataLabel.text = object.model.successDate;
    self.accountDateLabel.text = object.model.accountDate;
    self.outDateLabel.text = object.model.outDate;
    self.bearingDateLabel.text = object.model.bearingDate;
    self.inDateLabel.text = object.model.inDate;
    
    self.successImageView.image = CYImage(@"invest_progress_success_d");
    self.accountImageView.image = CYImage(@"invest_progress_account_d");
    self.outImageView.image = CYImage(@"invest_progress_out_d");
    self.bearingImageView.image = CYImage(@"invest_progress_bearing_d");
    self.inImageView.image = CYImage(@"invest_progress_in_d");
    
    self.successLabel.textColor = HEXCOLOR(@"999999");
    self.accountLabel.textColor = HEXCOLOR(@"999999");
    self.outLabel.textColor = HEXCOLOR(@"999999");
    self.bearingLabel.textColor = HEXCOLOR(@"999999");
    self.inLabel.textColor = HEXCOLOR(@"999999");
    
    self.accountLine.backgroundColor = HEXCOLOR(@"ECECEC");
    self.outLine.backgroundColor = HEXCOLOR(@"ECECEC");
    self.bearingLine.backgroundColor = HEXCOLOR(@"ECECEC");
    self.inLine.backgroundColor = HEXCOLOR(@"ECECEC");
    
    if(object.model.progress >= CYInvestProgressSuccess)
    {
        self.successImageView.image = CYImage(@"invest_progress_success_e");
        self.successLabel.textColor = APP_DEFAULT_COLOR_BLUE;
    }
    if(object.model.progress >= CYInvestProgressAccount)
    {
        self.accountLine.backgroundColor = HEXCOLOR(@"D8E8FA");
        self.accountImageView.image = CYImage(@"invest_progress_account_e");
        self.accountLabel.textColor = APP_DEFAULT_COLOR_BLUE;
    }
    if(object.model.progress >= CYInvestProgressOut)
    {
        self.outLine.backgroundColor = HEXCOLOR(@"D8E8FA");
        self.outImageView.image = CYImage(@"invest_progress_out_e");
        self.outLabel.textColor = APP_DEFAULT_COLOR_BLUE;
    }
    if(object.model.progress >= CYInvestProgressBearing)
    {
        self.bearingLine.backgroundColor = HEXCOLOR(@"D8E8FA");
        self.bearingImageView.image = CYImage(@"invest_progress_bearing_e");
        self.bearingLabel.textColor = APP_DEFAULT_COLOR_BLUE;
    }
    if(object.model.progress >= CYInvestProgressIn)
    {
        self.inLine.backgroundColor = HEXCOLOR(@"D8E8FA");
        self.inImageView.image = CYImage(@"invest_progress_in_e");
        self.inLabel.textColor = APP_DEFAULT_COLOR_BLUE;
    }
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.successImageView.left = 20;
    self.successImageView.top = 40;
    
    self.accountLine.centerX = self.successImageView.centerX;
    self.accountLine.top = self.successImageView.centerY;
    
    self.accountImageView.left = 20;
    self.accountImageView.centerY = self.accountLine.bottom;
    
    self.outLine.centerX = self.successImageView.centerX;
    self.outLine.top = self.accountImageView.centerY;
    
    self.outImageView.left = 20;
    self.outImageView.centerY = self.outLine.bottom;
    
    self.bearingLine.centerX = self.accountImageView.centerX;
    self.bearingLine.top = self.outImageView.centerY;
    
    self.bearingImageView.left = 20;
    self.bearingImageView.centerY = self.bearingLine.bottom;
    
    self.inLine.centerX = self.successImageView.centerX;
    self.inLine.top = self.bearingImageView.centerY;
    
    self.inImageView.left = 20;
    self.inImageView.centerY = self.inLine.bottom;
    
    self.successLabel.centerY = self.successImageView.centerY - 8;
    self.successLabel.left = 62;
    
    [self.successDataLabel sizeToFit];
    self.successDataLabel.left = 62;
    self.successDataLabel.centerY = self.successImageView.centerY + 11;
    
    self.accountLabel.centerY = self.accountImageView.centerY - 8;
    self.accountLabel.left = 62;
    
    [self.accountDateLabel sizeToFit];
    self.accountDateLabel.left = 62;
    self.accountDateLabel.centerY = self.accountImageView.centerY + 11;
    
    self.outLabel.centerY = self.outImageView.centerY - 8;
    self.outLabel.left = 62;
    
    [self.outDateLabel sizeToFit];
    self.outDateLabel.left = 62;
    self.outDateLabel.centerY = self.outImageView.centerY + 11;
    
    self.bearingLabel.centerY = self.bearingImageView.centerY - 8;
    self.bearingLabel.left = 62;
    
    [self.bearingDateLabel sizeToFit];
    self.bearingDateLabel.left = 62;
    self.bearingDateLabel.centerY = self.bearingImageView.centerY + 11;
    
    self.inLabel.left = 62;
    self.inLabel.centerY = self.inImageView.centerY - 8;
    
    [self.inDateLabel sizeToFit];
    self.inDateLabel.left = 62;
    self.inDateLabel.centerY = self.inImageView.centerY + 11;
}

#pragma mark - Private Method
- (UIImageView *)stateImageView
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
    return imageView;
}

- (UILabel *)labelWithText:(NSString *)text
{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:16];
    label.text = text;
    [label sizeToFit];
    return label;
}

- (UILabel *)dateLabel
{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = HEXCOLOR(@"999999");
    return label;
}

- (UIView *)line
{
    UIView *view = [[UIView alloc] init];
    view.width = 1;
    view.height = 61;
    return view;
}

@end
